import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { RepoForm, RepoInfoVo, RepoQuery, RepoVO } from '@/api/exam/repo/types';


const apiPrefix = '/exam/repo/';
/**
 * 查询题库分页列表
 * @param query
 * @returns {*}
 */
export const pageRepo = (query?: RepoQuery): AxiosPromise<RepoVO[]> => {
  return request({
    url: apiPrefix + 'page',
    method: 'get',
    params: query
  });
};

/**
 * 查询题库列表
 * @param query
 * @returns {*}
 */
export function listRepo(query?: RepoQuery|null): AxiosPromise<RepoVO[]> {
  return request({
    url: apiPrefix + 'list',
    method: 'get'
  });
}

/**
 * 查询题库列表（包含题目）
 * @param query
 * @returns {*}
 */
export function listRepoAndTemplate(query?: RepoQuery|null): AxiosPromise<RepoInfoVo[]> {
  return request({
    url: apiPrefix + 'listAndTemplate',
    method: 'get'
  });
}

/**
 * 查询题库详细
 * @param repoId
 */
export const getRepo = (repoId: string | number): AxiosPromise<RepoVO> => {
  return request({
    url: apiPrefix + repoId,
    method: 'get'
  });
};

/**
 * 新增题库
 * @param data
 */
export const addRepo = (data: RepoForm) => {
  return request({
    url: apiPrefix,
    method: 'post',
    data: data
  });
};

/**
 * 修改题库
 * @param data
 */
export const updateRepo = (data: RepoForm) => {
  return request({
    url: apiPrefix,
    method: 'put',
    data: data
  });
};

/**
 * 删除题库
 * @param repoId
 */
export const delRepo = (repoId: string | number | Array<string | number>) => {
  return request({
    url: apiPrefix + repoId,
    method: 'delete'
  });
};

/*从题库挑选题目*/
export const pickQuestion = (data : any) => {
  return request({
    url: apiPrefix + 'pick',
    method: 'post',
    data: data
  });
};

/**
 * 题库图片上传
 * @param data 头图片文件
 */
export const uploadImage = (data: FormData) => {
  return request({
    url: apiPrefix + 'image',
    method: 'post',
    data: data
  });
};
